package com.leetcode.www;

import java.util.Arrays;

/**
 * Creared with IntelliJ IDEA.
 * Description:给定两个字符串 s1 和 s2，请编写一个程序，确定其中一个字符串的字符重新排列后，能否变成另一个字符串。
 * User:yxd
 * Date:2022-01-20
 * Time:23:01
 */
public class Interview0102 {
    public static void main(String[] args) {
        String s1 = "acb";
        String s2 = "cab";
        System.out.println(CheckPermutation(s1, s2));
    }
    public static boolean CheckPermutation(String s1, String s2) {
        if(s1 == null && s2 == null){
            return true;
        }
        if(s1 == null || s2 == null){
            return false;
        }
        if(s1.length() != s2.length()){
            return false;
        }
        char[] a = s1.toCharArray();
        char[] a1 = s2.toCharArray();
        Arrays.sort(a);
        Arrays.sort(a1);
        if(new String(a).equals(new String(a1))){//排序后放入新的字符串如果相等就正确
            return true;
        }else{
            return false;
        }
    }
}
